package com.jobson.view;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.ejb.Stateful;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Named;

import org.primefaces.event.SelectEvent;

import com.jobson.model.Customer;
import com.jobson.model.Transcation.CustomerT;

/**
 * Backing bean for Customer entities.
 * <p>
 * This class provides CRUD functionality for all Customer entities. It focuses purely on Java EE 6 standards (e.g.
 * <tt>&#64;ConversationScoped</tt> for state management, <tt>PersistenceContext</tt> for persistence,
 * <tt>CriteriaBuilder</tt> for searches) rather than introducing a CRUD framework or custom base class.
 */

@Named
@Stateful
@ConversationScoped
public class CustomerBean implements Serializable {

    private static final long serialVersionUID = 1L;
    private final Customer _customer;
    private boolean allCustomers;
    private boolean onlyRealCustomer;
    private boolean onlyDummyCustomer;
    private String searchFilter;
    private List<Customer> customerList;
    private List<Customer> selectedCustomerList;
    private Customer selectedCustomer;

    public CustomerBean() {
        _customer = new Customer();
        selectedCustomer = new Customer();
        customerList = new ArrayList<Customer>();
    }

    public void updateCustomers() {
        setCustomerList(new CustomerT().findLikeCustomer(searchFilter));
    }

    public void onRowSelect(SelectEvent event) {
        Customer cus = getSelectedCustomerList().get(0);
        setSelectedCustomer(cus);
    }

    public boolean isAllCustomers() {
        return allCustomers;
    }

    public void setAllCustomers(boolean allCustomers) {
        this.allCustomers = allCustomers;
    }

    public boolean isOnlyRealCustomer() {
        return onlyRealCustomer;
    }

    public void setOnlyRealCustomer(boolean onlyRealCustomer) {
        this.onlyRealCustomer = onlyRealCustomer;
    }

    public boolean isOnlyDummyCustomer() {
        return onlyDummyCustomer;
    }

    public void setOnlyDummyCustomer(boolean onlyDummyCustomer) {
        this.onlyDummyCustomer = onlyDummyCustomer;
    }

    public Customer get_customer() {
        return _customer;
    }

    public String getSearchFilter() {
        return searchFilter;
    }

    public void setSearchFilter(String searchFilter) {
        this.searchFilter = searchFilter;
    }

    public List<Customer> getCustomerList() {
        return customerList;
    }

    public void setCustomerList(List<Customer> customerList) {
        this.customerList = customerList;
    }

    public List<Customer> getSelectedCustomerList() {
        return selectedCustomerList;
    }

    public void setSelectedCustomerList(List<Customer> selectedCustomerList) {
        this.selectedCustomerList = selectedCustomerList;
    }

    public Customer getSelectedCustomer() {
        return selectedCustomer;
    }

    public void setSelectedCustomer(Customer selectedCustomer) {
        this.selectedCustomer = selectedCustomer;
    }

}